FROM docker.io/debian:trixie AS buildEnv
RUN apt update && apt install -y gcc g++ cmake ninja-build thrift-compiler git libyaml-cpp-dev libspdlog-dev libthrift-dev libboost-all-dev nlohmann-json3-dev libstb-dev cppzmq-dev libmsgpack-cxx-dev libyaml-cpp-dev
WORKDIR /
COPY . /SuperMatrix
RUN cd SuperMatrix && mkdir build-standalone && cd build-standalone && cmake .. -DCMAKE_BUILD_TYPE=Release  -DDISABLE_TEST=Off -DBUILD_DEVICE=StandAlone -G Ninja && ninja && ninja install

FROM busybox:glibc
COPY --from=buildEnv /SuperMatrix/build-standalone/Client/ThriftClient /bin
COPY --from=buildEnv /SuperMatrix/build-standalone/Stand-Alone/StandAlone /bin
COPY --from=buildEnv /usr/bin/bash /bin
COPY --from=buildEnv /usr/lib/aarch64-linux-gnu/ /lib/
COPY --from=buildEnv /usr/local/lib/ /lib/ 

ARG S6_OVERLAY_VERSION=3.1.6.2
ARG ARCH=aarch64
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${ARCH}.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-aarch64.tar.xz

COPY Stand-Alone/docker/s6/ /etc/services.d/
RUN chmod +x /etc/services.d/client/run && chmod +x /etc/services.d/client/finish && chmod +x /etc/services.d/standalone/run

CMD ["/init"]

